use std::{error::Error, path::{Path, PathBuf}};

use tiled::Loader;
use geometry::TmxData;

mod transformation;

mod map;

mod layer;

mod navmesh;

pub mod geometry;

pub mod visual_data;

pub(crate) struct MapData{
    pub map: tiled::Map,
    pub work_dir: PathBuf,
}

pub fn load_tmx(path: impl AsRef<Path>, work_dir: impl AsRef<Path>)->Result<TmxData, Box<dyn Error>>  {
    let mut loader = Loader::new();
    let map = loader.load_tmx_map(&path)?;

    let map = MapData{
        map,
        work_dir: work_dir.as_ref().to_path_buf().canonicalize()?,
    };
    Ok(TmxData::from(map))
}
